<template>
  <div class="Comment">
    <!-- 头部 -->
    <div>
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <!-- 首页 -->
          <myel-header text1="首页" text2="评论管理"></myel-header>
        </div>
        <!-- 下面 -->
        <div>
          <!-- 渲染的内容 -->
          <el-table
            :data="tableData.results"
            stripe
            style="width: 100%"
            @cell-click="qwe"
            current-row-key
          >
            <el-table-column prop="title" label="发表文章"></el-table-column>
            <el-table-column prop="total_comment_count" label="总评论数"></el-table-column>
            <el-table-column prop="fans_comment_count" label="粉丝评论数"></el-table-column>
            <el-table-column prop="zheng" label="评论状态"></el-table-column>
            <el-table-column label="操作" prop="dakai"></el-table-column>
          </el-table>
          <el-pagination
            :page-size="tableData.per_page"
            background
            layout="prev, pager, next"
            :total="tableData.total_count"
            :current-page="tableData.page"
            @current-change="fenyegai"
          ></el-pagination>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
// 头部
import MyelHeader from '../../components/MyelHeader.vue'
// 调接口
import { getarticles } from '../../api/articles.js'
export default {
  name: 'Comment',
  components: {
    MyelHeader
  },
  data () {
    return {
      tableData: []
    }
  },
  created () {
    this.getComment()
  },
  methods: {
    async getComment () {
      const { data: { data } } = await getarticles({
        response_type: 'comment',
        page: this.tableData.page
      })
      data.results.forEach(res => {
        if (res.comment_status) {
          res.zheng = '正常'
          res.dakai = <el-button type="success">打开评论</el-button>
        } else {
          res.zheng = '关闭'
          res.dakai = <el-button type="danger">关闭评论</el-button>
        }
      })
      this.tableData = data
      console.log(data)
    },
    fenyegai (res) {
      this.tableData.page = res
      this.getComment()
    },
    qwe (row, column, cell, event) {
      if (row.zheng === '正常') {
        row.zheng = '关闭'
        row.dakai = <el-button type="danger">关闭评论</el-button>
      } else {
        row.zheng = '正常'
        row.dakai = <el-button type="success">打开评论</el-button>
      }
    }
  }

}
</script>

<style lang="less" scoped>
</style>
